// (byteorder.c:在一个短整型变量中存放2字节的值0x0102，然后查看它的两个连续字节c[0]和c[1]，以此确定主机字节序)
#include <stdio.h>

int main(int argc, char **argv) {
	union {
	  short  s;
	  char   c[sizeof(short)];
	} un;

	un.s = 0x0102;
	printf("Host byte order: ");
	if (2 == sizeof(short)) {
		if (un.c[0] == 1 && un.c[1] == 2)
			printf("big-endian\n");
		else if (un.c[0] == 2 && un.c[1] == 1)
			printf("little-endian\n");
		else
			printf("unknown\n");
	} else
		printf("sizeof(short) = %d\n", sizeof(short));

	return 0;
}
